import {VxeFormInstance} from "vxe-pc-ui";
import XEUtils from "xe-utils";

export class FormRuleValidateUtils {

    public static async validate<T>(formRef: VxeFormInstance<T> | undefined): Promise<void> {
        if (!formRef) {
            // 直接 throw 更清晰
            throw new Error("Form ref is undefined");
        }

        // 等待验证结果
        const errMap = await formRef.validate();
        if (!XEUtils.isUndefined(errMap)) {
            // 验证失败时 reject
            throw new Error("Validation failed");
        }

        // 成功时隐式返回 resolve(undefined)
    }
}
